﻿using System;
using System.Diagnostics;

namespace XTrace.Compatibility
{
#pragma warning disable 612,618
	public sealed class BridgeFromXTraceToTrace : TextXTraceListener
#pragma warning restore 612,618
	{
		protected override void WriteLine(string line)
		{
			//lock (WritingToTraceSync)
			{
				if (WritingToTrace)
				{
					throw new InvalidOperationException("Something wrong - recurring trace");
				}
				try
				{
					WritingToTrace = true;
					Trace.WriteLine(line);
				}
				finally
				{
					WritingToTrace = false;
				}
			}
		}

#if !PocketPC
		[ThreadStatic]
#endif
		internal static bool WritingToTrace;

//#if !PocketPC
//		[ThreadStatic]
//#endif
//		internal static readonly object WritingToTraceSync = new object();
	}
}